package com.zhengxing.jienci.web.pojo;


import com.zhengxing.jienci.web.enums.ResultCode;

/**
 * @author 浪遏飞舟
 * @create 2020-06-23 11:11
 * 统一返回对象
 */
public class ResultVo<T> {

    //状态码
    private String code;

    //消息
    private String msg;

    //数据
    private T data;

    public ResultVo(ResultCode resultCode, T data){
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public ResultVo(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static ResultVo success(){
        return success(null);
    }

    public static ResultVo success(Object data){
        return new ResultVo(ResultCode.SUCCESS,data);
    }

    public static ResultVo success(String msg,Object data){
        return new ResultVo(ResultCode.SUCCESS.getCode(),msg,data);
    }

    public static ResultVo warn(Object data){
        return new ResultVo(ResultCode.WARN,data);
    }

    public static ResultVo error(){
        return error(null);
    }

    public static ResultVo error(String msg){
        return new ResultVo(ResultCode.ERROR.getCode(),msg,null);
    }

    public static ResultVo<String> error(String msg,String data){
        return new ResultVo(ResultCode.ERROR.getCode(),msg,data);
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
